<template>
  <div class="bor">
    <!-- 上面两台 -->
    <div>
      <div class="workOrder">
        <div class="bgi">
          工单统计
          <span>2002</span>
          <el-row>
            <el-col :span="6"><div class="grid-content bg-purple" />
              <div>{{ total }}</div>
              <div>工单总数(个)</div>
            </el-col>
            <el-col :span="6"><div class="grid-content bg-purple-light">
              <div>{{ completedTotal }}</div>
              <div>完成工单(个)</div>
            </div></el-col>
            <el-col :span="6"><div class="grid-content bg-purple">
              <div>{{ progressTotal }}</div>
              <div>进行工单(个)</div>
            </div></el-col>
            <el-col :span="6"><div class="grid-content bg-purple-light">
              <div>{{ cancelTotal }}</div>
              <div>取消工单(个)</div>
            </div></el-col>
          </el-row>
        </div>
      </div>
      <div class="sell">销售统计
        <span>2002</span>
        <el-row>
          <el-col :span="12"><div class="grid-content bg-purple" />
            <div>255</div>
            <div>总数</div>
          </el-col>
          <el-col :span="12"><div class="grid-content bg-purple-light">
            <div>255</div>
            <div>总数</div>
          </div></el-col>
        </el-row>
      </div>
    </div>

  </div>
</template>

<script>
import moment from 'moment'
import { condition, Sales } from '@/api'
export default {
  name: 'Dashboard',

  data() {
    return {
      start: '2022-10-01 00:00:00', // 开始
      sStart: '2022-10-01',
      end: this.formatDate(new Date().getTime()), // 结束
      sEnd: this.SalesData(new Date().getTime()), // 结束
      total: 0, // 工单总数
      completedTotal: 0, // 完成数
      progressTotal: 0, // 进行中
      cancelTotal: 0 // 取消数
    }
  },
  async created() {
    // 工单统计的接口
    const { data } = await condition(this.start, this.end)
    data.forEach(item => {
      this.total += item.total
      this.completedTotal += item.completedTotal
      this.cancelTotal += item.cancelTotal
      this.progressTotal += item.progressTotal
    })
    console.log(data)
    // 销售额统计
    const res = await Sales(this.sStart, this.sEnd)
    console.log(res)
  },
  methods: {
    // 带时分秒
    formatDate(val) {
      return moment(val).format('YYYY-MM-DD' + ' HH:mm:ss')
    },
    // 不带时分秒
    SalesData(val) {
      return moment(val).format('YYYY-MM-DD')
    }
  }

}
</script>
<style lang="scss" scoped>
.bor{
  padding: 20px;
}
.workOrder {
  display: inline-block;
  width: 500px;
  height: 130px;
  border-radius: 30px;
background:#e9f3ff url(http://likede2-admin.itheima.net/img/task.66b715b7.png) no-repeat calc(100% - 12px) 100%;
  margin-right: 20px;
  padding: 20px;
}
.sell{
  display: inline-block;
   width: 400px;
  height: 130px;
  border-radius: 30px;
  // background-color: #fbefe8;
  background: #fbefe8 url(http://likede2-admin.itheima.net/img/sale.606b0d8c.png) no-repeat calc(100% - 12px) 100%;
  padding: 20px;

}
.bgi {
}
</style>
